﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm_Comparison
{
    class Point
    {
        public readonly int Dimension;
        public double[] Coordinates;
        public Point(int dimension, double[] coordinates)
        {
            Dimension = dimension;
            Coordinates = coordinates;
        }
        public Point(int dimension) : this(dimension, new double[dimension]) {}

        public Point(Point original) : this(original.Dimension, (double[])original.Coordinates.Clone())
        {
            
        }

        /// <summary>
        /// Calculates the distance between this point and otherPoint
        /// </summary>
        /// <param name="otherPoint"></param>
        /// <param name="euclidian">Whether or not to use euclidian distance</param>
        /// <returns></returns>
        public double DistanceTo(Point otherPoint, bool euclidian=true)
        {
            if (otherPoint.Dimension != Dimension)
                throw new ArgumentException("other needs to have same dimension", "other");

            double result = 0;

            if (euclidian)
            {
                for (int column = 0; column < Dimension; column++)
                    result += Math.Pow(Coordinates[column] - otherPoint.Coordinates[column], 2);
                return Math.Sqrt(result);
            }
            else
            {

                for (int column = 0; column < Dimension; column++)
                    result += Math.Abs(Coordinates[column] - otherPoint.Coordinates[column]);
                return result;
            }
        }
    }
}
